import axios from 'axios'
import { baseURL } from './tools'
import nProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 创建axios实例
const instance = axios.create({
  baseURL,
  timeout: 5000
})
// 请求拦截器
instance.interceptors.request.use(
  (config) => {
    nProgress.start()
    return config
  },
  (err) => {
    return Promise.reject(err)
  }
)
// 响应拦截器
instance.interceptors.response.use(
  (res) => {
    nProgress.done()
    return res.data
  },
  (err) => {
    return Promise.reject(err)
  }
)
// 暴露get请求
export const get = (url, params) => {
  return instance.get(url, {
    params
  })
}
// 暴露post请求
export const post = (url, data) => {
  return instance.post(url, data)
}
// 暴露put请求
export const put = (url, data) => {
  return instance.put(url, data)
}
// 暴露delete请求
export const deleteRequest = (url, data) => {
  return instance.delete(url, data)
}
